package com.szpx.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.szpx.entity.Vip;
import com.szpx.entity.VipInformation;
import com.szpx.service.VipInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class VipInformationController {

    @Autowired
    private VipInformationService vipInformationService;

    @GetMapping("/selectVinformationById/{id}")
    public String selectVinformation(@PathVariable("id") Integer id, Model model) {
        VipInformation vipInformation = vipInformationService.selectVinformationById(id);
        if (vipInformation != null){
            model.addAttribute("vipInformation",vipInformation);
            return "zx/zx_VipInformationHtml/zx_VipInformation";
        }else {
            return null;
        }
    }



    /**
     * 多条件分页查询所有影片
     */
    @GetMapping("/vlist")
    public String getVlist(
            @RequestParam(defaultValue = "1") int pno,
            @RequestParam(defaultValue = "10") int pageSize,
            VipInformation vipInformation, Model model){
        PageHelper.startPage(pno,pageSize);//开始分页
        List<VipInformation> vlist = vipInformationService.getListByMation(vipInformation);
        PageInfo<VipInformation> page = new PageInfo<VipInformation>(vlist);
        model.addAttribute("vlist",vlist); //将查询到的数据放入model对象中
        model.addAttribute("page",page);
        model.addAttribute("grade",vipInformation.getGrade());
        model.addAttribute("score",vipInformation.getScore());
        model.addAttribute("pno",pno);
        return "zx/zx_VipInformationHtml/zx_VipInformationList";
    }

}
